package com.bwie.service.impl;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.bwie.common.domain.request.ShopListRequest;
import com.bwie.common.domain.response.ShopListResponse;
import com.bwie.domain.EsShop;
import com.bwie.mapper.EsShopMapper;
import com.bwie.service.EsShopService;
import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author <a href="mailto:3364114353@qq.com">liuwenliang</a>
 * @version 1.0
 * @description:
 * @date 2025/9/9 11:59
 */
@Service
public class EsShopServiceImpl implements EsShopService {

    @Autowired
    private EsShopMapper esShopMapper;

    @Override
    public void createIndex() {
        esShopMapper.createIndex();
    }

    @Override
    public EsPageInfo<EsShop> esPage(ShopListRequest shopListRequest) {
        LambdaEsQueryWrapper<EsShop> wrapper = new LambdaEsQueryWrapper<>();
        String shopName = shopListRequest.getShopName();
        if (StrUtil.isNotBlank(shopName)) {
            wrapper.match(EsShop::getShopName,shopName);
        }
        Date enterTimeMin = shopListRequest.getEnterTimeMin();
        if (ObjUtil.isNotNull(enterTimeMin)) {
            wrapper.le(EsShop::getEndTime,enterTimeMin);
        }
        Date enterTimeMax = shopListRequest.getEnterTimeMax();
        if (ObjUtil.isNotNull(enterTimeMax)) {
            wrapper.ge(EsShop::getEnterTime,enterTimeMax);
        }
        //分页，返回
        EsPageInfo<EsShop> esShopEsPageInfo = esShopMapper.pageQuery(wrapper, shopListRequest.getPageNum(), shopListRequest.getPageSize());
        return esShopEsPageInfo;
    }
}
